package ITSBank;


import java.util.*;

/**
 * This class represents a customer
 * @author Benedikt Gschossmann
 */
public class Customer {
    private int CustomerID;
    private String CustomerName;
    private String CustomerAddress;
    private Bank CustomerBank;
    private ArrayList<Integer> accountsIDs;
    private String PIN;
    private boolean trusted;

    /**
     * Constructor for class Customer
     * @param cID
     * @param cName
     * @param cAddress
     * @param cBank
     */
    public Customer(int CustomerID, String CustomerName, String CustomerAddress, Bank CustomerBank) {
        this.CustomerID = CustomerID;
        this.CustomerName = CustomerName;
        this.CustomerAddress = CustomerAddress;
        this.CustomerBank = CustomerBank;
        Random generator = new Random();
        String pintemp=Integer.toString(generator.nextInt(9998)+1);
        while (pintemp.length()<4)
        {pintemp="0".concat(pintemp);
        }
        this.PIN = pintemp;
        this.accountsIDs = new ArrayList();
        this.trusted = false;
    }

    /**
     * Get-method for cName
     * @return name of customer
     */
    public String getCustomerName() {
        return CustomerName;
    }

    public void setTrusted(boolean trusted){
        this.trusted = trusted;
    }

    public boolean isTrusted(){
        return this.trusted;
    }

    public String getPIN(){
        return PIN;
    }

    public void addAccount(int newAccountID){
        this.accountsIDs.add(newAccountID);
    }
    /**
     * Get-method for cAddress
     * @return address of customer
     */
    public String getCustomerAddress () {
        return CustomerAddress;
    }

    /**
     * Get-method for cID
     * @return ID of the customer
     */
    public int getCustomerID () {
        return CustomerID;
    }

    /**
     * This method changes the address of a customer
     * @param newAddress
     */
    public void setCustomerAddress (String newAddress) {
        CustomerAddress = newAddress;
    }

    /**
     * Get-method for CustomerBank
     * @return bankID of customers bank
     */
    public Bank getCustomerBank () {
        return CustomerBank;
    }
    /**
     * Set-method for CustomerID
     */
    public void setCusomerID(int custID){
        this.CustomerID=custID;
    }
    /**
     * Set-method for CustomerBank
     */
    public void setCustomerBank(Bank bank) {
        this.CustomerBank=bank;
    }

    public void ShowCustomerDetails() {
        System.out.println("CustomerID is: "+this.CustomerID);
        System.out.println("Customers Bank is: "+this.CustomerBank.getBankName());
        System.out.println("Customers name is: "+this.CustomerName);
        System.out.println("Customer address is: "+this.CustomerAddress);
        for ( Iterator i = this.accountsIDs.iterator(); i.hasNext(); )
        {
            Account acc = this.getCustomerBank().getAccount((Integer)i.next());
            System.out.println("Customer owns account "+acc.getAccountNumber()+" where he has: "+acc.getBalance());
            acc.displayTransactionHistory();
        }

    }
}

